package com.dai.spec.gxk.controller;

import com.dai.spec.common.annotation.Log;
import com.dai.spec.common.core.controller.BaseController;
import com.dai.spec.common.core.page.TableDataInfo;
import com.dai.spec.common.enums.BusinessType;
import com.dai.spec.common.enums.CourseCycleType;
import com.dai.spec.common.enums.CourseType;
import com.dai.spec.common.enums.DeliveryType;
import com.dai.spec.common.utils.poi.ExcelUtil;
import com.dai.spec.gxk.request.MyScorePageRequest;
import com.dai.spec.gxk.service.MyScoreService;
import com.dai.spec.gxk.vo.MyScoreVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 学生成绩信息管理Controller
 * 学生接口，管理学生已选课程的成绩信息
 * @author daikl
 * @date 2024-03-12
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/gxk/myScore")
@Api("学生/我的成绩管理")
public class MyScoreController extends BaseController {
    private MyScoreService myScoreService;

    public MyScoreController(MyScoreService myScoreService) {
        this.myScoreService = myScoreService;
    }

    /**
     * 查询我的学生成绩列表
     */
    @ApiOperation("查询我的成绩列表")
    @PreAuthorize("@ss.hasPermi('gxk:myScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyScorePageRequest pageRequest) {

        List<MyScoreVO> list = myScoreService.queryMyScoreList(pageRequest);
        return getDataTable(list);
    }
    /**
     * 导出我的成绩信息管理列表
     */
    @ApiOperation("导出我的成绩列表")
    @PreAuthorize("@ss.hasPermi('gxk:myScore:export')")
    @Log(title = "我的学生成绩信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyScorePageRequest pageRequest) {

        List<MyScoreVO> list = myScoreService.queryMyScoreList(pageRequest);
        List<MyScoreVO> studentScoreVOList = list.stream().map(item -> {
            item.setDeliveryType(DeliveryType.getValueByCode(item.getDeliveryType()));
            item.setCourseCycle(CourseCycleType.getValueByCode(item.getCourseCycle()));
            item.setType(CourseType.getValueByCode(item.getType()));
            return item;
        }).collect(Collectors.toList());
        ExcelUtil<MyScoreVO> util = new ExcelUtil<>(MyScoreVO.class);
        util.exportExcel(response, studentScoreVOList, "我的成绩信息管理数据");
    }
}
